package com.sdb.patientinfo.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sdb.common.annotation.Log;
import com.sdb.common.core.controller.BaseController;
import com.sdb.common.core.domain.AjaxResult;
import com.sdb.common.enums.BusinessType;
import com.sdb.patientinfo.domain.TdPatientinfo;
import com.sdb.patientinfo.service.ITdPatientinfoService;
import com.sdb.common.utils.poi.ExcelUtil;
import com.sdb.common.core.page.TableDataInfo;

/**
 * 病人详细信息Controller
 * 
 * @author yyh
 * @date 2025-01-24
 */
@RestController
@RequestMapping("/patientinfo/patientinfo")
public class TdPatientinfoController extends BaseController
{
    @Autowired
    private ITdPatientinfoService tdPatientinfoService;

    /**
     * 查询病人详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/list")
    public TableDataInfo list(TdPatientinfo tdPatientinfo)
    {
        startPage();
        List<TdPatientinfo> list = tdPatientinfoService.selectTdPatientinfoList(tdPatientinfo);
        return getDataTable(list);
    }

    /**
     * 导出病人详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病人详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TdPatientinfo tdPatientinfo)
    {
        List<TdPatientinfo> list = tdPatientinfoService.selectTdPatientinfoList(tdPatientinfo);
        ExcelUtil<TdPatientinfo> util = new ExcelUtil<TdPatientinfo>(TdPatientinfo.class);
        util.exportExcel(response, list, "病人详细信息数据");
    }

    /**
     * 获取病人详细信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return success(tdPatientinfoService.selectTdPatientinfoByPatientId(patientId));
    }

    /**
     * 新增病人详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病人详细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TdPatientinfo tdPatientinfo)
    {
        return toAjax(tdPatientinfoService.insertTdPatientinfo(tdPatientinfo));
    }

    /**
     * 修改病人详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病人详细信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TdPatientinfo tdPatientinfo)
    {
        return toAjax(tdPatientinfoService.updateTdPatientinfo(tdPatientinfo));
    }

    /**
     * 删除病人详细信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @Log(title = "病人详细信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable Long[] patientIds)
    {
        return toAjax(tdPatientinfoService.deleteTdPatientinfoByPatientIds(patientIds));
    }

    /**
     * 查询历次就诊信息
     */
    @PreAuthorize("@ss.hasPermi('index')")
    @GetMapping("/visit/{cardId}")
    public TableDataInfo visit(@PathVariable("cardId") String cardId)
    {
        List<TdPatientinfo> list = tdPatientinfoService.selectDiagnosis(cardId);
        return getDataTable(list);
    }
}
